export function sleep(ms: number) {
  return new Promise(resolve => {
    setTimeout(resolve, ms);
  });
}

export function isArray(val: any) {
  return val?.length && Array.isArray(Array.from(val));
}

export function getNested(obj: object, ...args: any[]) {
  return args.reduce((obj, level) => obj && obj[level], obj);
}

export function isJson(str: string) {
  try {
    JSON.parse(str);
  } catch (e) {
    return false;
  }
  return true;
}
